home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0150_Loading 256 Color Bitmaps.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  2KB  |  80 lines

  1. {
  2. For all who are interested:
  3. }
  4. {------------------------------------------------------------------------}
  5. {  HOW TO READ A .BMP FILE!                                              }
  6. {------------------------------------------------------------------------}
  7. procedure LoadBMP(dx:integer;dy:byte;usepal:boolean;filestr:string);
  8.   {Loads a 256-color .BMP file directly onto}
  9.   {the screen at point x,y; K.Gale, 8/23/94}
  10.   {added option to use or not use the saved palette; 8/24/94}
  11. var
  12.    cel:text;
  13.    inchar:char;
  14.    instr:string[4];
  15.    y,r,g,b,ymax:byte;
  16.    x,xmax:integer;
  17. const
  18.      bmpheader=18;
  19. begin
  20.      x:=0;y:=0;
  21.      assign(cel,filestr);
  22.      reset(cel);
  23.      for x:=1 to bmpheader do
  24.          read(cel,inchar);
  25.      x:=0;
  26.      read(cel,instr);
  27.      xmax:=ord(instr[1])+(ord(instr[2])*256)
  28.           +(ord(instr[2])*256*256)+(ord(instr[3])*256*256*256)-1;
  29.      read(cel,instr);
  30.      ymax:=ord(instr[1])+(ord(instr[2])*256)
  31.           +(ord(instr[2])*256*256)+(ord(instr[3])*256*256*256)-1;
  32.      for x:=27 to 54 do
  33.          read(cel,inchar);
  34.      x:=0;
  35.      if usepal<>false then
  36.         begin
  37.              for y:=0 to 255 do
  38.                  pal(y,0,0,0);
  39.              y:=0;
  40.              while x<=255 do
  41.              begin
  42.                   read(cel,instr);
  43.                   r:=ord(instr[3]) div 4;
  44.                   g:=ord(instr[2]) div 4;
  45.                   b:=ord(instr[1]) div 4;
  46.                   pal(x,r,g,b);
  47.                   inc(x,1)
  48.              end
  49.         end
  50.      else
  51.          for x:=0 to 255 do
  52.              read(cel,instr);
  53.      x:=0;
  54.      while (y<=ymax) do
  55.      begin
  56.           read(cel,inchar);
  57.           putpixel(dx+x,dy+(ymax-y),ord(inchar),vga);
  58.           if x<xmax then
  59.              inc(x,1)
  60.           else
  61.               begin
  62.                    inc(y,1);
  63.                    x:=0;
  64.               end
  65.      end;
  66.      close(cel)
  67. end;
  68. {------------------------------------------------------------------------}
  69.  
  70. There...
  71. never mind the putpixel procedure call...
  72. you DO NOT have that procedure.  I use a gfx unit that
  73. a friend of mine wrote and so, you will have to substitute
  74. the proper procedure call for putting a pixel on the screen.
  75.  
  76. Furthermore, this will ONLY work for 256-color .BMP files.
  77. Lastly, the "usepal" boolean switch is for those cases when
  78. you want to preserve an already defined palette, rather than
  79. having the .BMP re-define all of those colors.
  80.